﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using Entidades;
namespace ADOConectado
{
    public static class dbMarcas
    {
        public static List<Marca> ListarMarcas(string paramMarca)
        {
            List<Marca> lstMarcas = new List<Marca>();
            SqlConnection objConexion = new SqlConnection(Conexiones.StringConexion);
            objConexion.Open();
            SqlCommand dataCommand = new SqlCommand("ListarMarcas", objConexion);
            dataCommand.CommandType = CommandType.StoredProcedure;
            if (paramMarca != "")
                dataCommand.Parameters.AddWithValue("@varMarca", paramMarca);
            else
                dataCommand.Parameters.AddWithValue("@varMarca", System.DBNull.Value);
            SqlDataReader objReader = dataCommand.ExecuteReader();
            try
            {
                while (objReader.Read())
                {
                    Marca objMarca = new Marca(Convert.ToInt32(objReader["intIdMarca"]), objReader["varMarca"].ToString());

                    lstMarcas.Add(objMarca);
                }
                return lstMarcas;
            }
            catch (Exception )
            {
                throw new System.ArgumentException("Parameter cannot be null", "original");
            }
            finally
            {
                objConexion.Close();
            }
        }

        public static void AgregarMarca(string paramMarcaNueva)
        {
            
            SqlConnection objConexion = new SqlConnection(Conexiones.StringConexion);
            objConexion.Open();
            SqlCommand dataCommand = new SqlCommand("AgregarMarca", objConexion);
            dataCommand.CommandType = CommandType.StoredProcedure;
            dataCommand.Parameters.AddWithValue("@varMarcaNueva", paramMarcaNueva);
            dataCommand.ExecuteNonQuery();
        }
            
    }
}
